package com.example.controller;

import com.example.domain.Result;
import com.example.domain.Zone;
import com.example.service.ZoneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/zones")
public class ZoneController {

    @Autowired
    private ZoneService zoneService;

    @GetMapping
    public Result getAll(){
        return new Result(true,zoneService.getAll());
    }

    @GetMapping("{zoneId}")
    public Result getById(@PathVariable Integer zoneId){
        return new Result(true,zoneService.getById(zoneId));
    }

    @PostMapping
    public Result add(@RequestBody Zone zone) {
        boolean code = zoneService.add(zone);
        return new Result(code);
    }

    @PutMapping
    public Result update(@RequestBody Zone zone){
        boolean code = zoneService.update(zone);
        return new Result(code);
    }

    @DeleteMapping("{zoneId}")
    public Result delete(@PathVariable Integer zoneId){
        boolean code = zoneService.delete(zoneId);
        return new Result(code);
    }

}
